<%@page contentType="text/html" pageEncoding="UTF-8"
        import="javax.swing.JOptionPane, Modelo.Persona, Modelo.Representante, java.util.List" %>
<%

            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Pragma", "no-cache");
            response.setDateHeader("Expires", -1);


            String tipo = request.getParameter("tipo");
            String id = request.getParameter("codigo");
            String pass = request.getParameter("clave");
            String opt = tipo.substring(0, 3);
            String idfuente = tipo.substring(3);

            if (id.equals("") || pass.equals("")) {
                response.sendRedirect("index.jsp");
            }
            Persona p = new Persona();
            Representante r = new Representante();
            if (opt.equals("op0")) {
                response.sendRedirect("index.jsp");
            }
            if (opt.equals("op1")) {
                if (p.validaLogin(id, pass, Long.parseLong(idfuente)) != null) {
                    List l = p.validaLogin(id, pass, Long.parseLong(idfuente));
                    HttpSession s = request.getSession();
                    s.invalidate();
                    HttpSession s2 = request.getSession();
                    s2.setAttribute("logged", true);
                    s2.setAttribute("tipo", "fuente");
                    s2.setAttribute("persona", l.get(0));
                    response.sendRedirect(request.getContextPath() + "/fuente/indexFuente.jsp");
                } else {
                    response.sendRedirect("index.jsp");
                }
            } else {
                if (opt.equals("op2") && idfuente.equals("5")) {
                    if (r.validaLogin(id, pass, idfuente) != null) {
                        List l2 = r.validaLogin(id, pass, idfuente);
                        HttpSession s = request.getSession();
                        s.invalidate();
                        HttpSession s2 = request.getSession();
                        s2.setAttribute("logged", true);
                        s2.setAttribute("tipo", "comiteCentral");
                        s2.setAttribute("representante", l2.get(0));
                        response.sendRedirect(request.getContextPath() + "/comiteCentral/indexComiteCentral.jsp");
                    } else {
                        response.sendRedirect("index.jsp");
                    }

                } else {
                    if (opt.equals("op2") && idfuente.equals("6")) {
                        if (r.validaLogin(id, pass, idfuente) != null) {
                            List l3 = r.validaLogin(id, pass, idfuente);
                            HttpSession s = request.getSession();
                            s.invalidate();
                            HttpSession s2 = request.getSession();
                            s2.setAttribute("logged", true);
                            s2.setAttribute("tipo", "comitePrograma");
                            s2.setAttribute("representante", l3.get(0));
                            response.sendRedirect(request.getContextPath() + "/comitePrograma/indexComitePrograma.jsp");
                        } else {
                            response.sendRedirect("index.jsp");
                        }

                    }

                }


            }

%>